<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>XMLHttpRequest_查询参数</title>
</head>

<body>
  <p class="city-p"></p>
  <script>
    /**
     * 目标：使用XHR携带查询参数，展示某个省下属的城市列表
    */

    const xhr = new XMLHttpRequest()
    // 进行查询 往服务器后面进行拼接查询的参数名 ?pname=
    xhr.open('GET', 'http://hmajax.itheima.net/api/city?pname=辽宁省')

    // loadend 加载结束事件
    xhr.addEventListener('loadend', () => {
      console.log(xhr.response)
      const data = JSON.parse(xhr.response)
      console.log(data.list)
      document.querySelector('.city-p').innerHTML = data.list.join('<br>')
    })

    xhr.send()

  </script>
</body>

</html>